//
//  NSDictionary+DY_EncryptionTools.m
//  Pods
//
//  Created by LXF on 16/6/30.
//
//

#import "NSDictionary+DY_EncryptionTools.h"
#import "NSString+DY_EncryptionTools.h"

@implementation NSDictionary (DY_EncryptionTools)


/// 明文 生成 密文 1 默认查找 key[password]
-(instancetype)dy_encryption1{
    return [self dy_encryption1WithKeys:@[@"password"]];
}

/// 密文1 调用 生成 密文2 默认查找 key[password]
-(instancetype)dy_encryption2_0ByDate:(NSString *)dateStamp{
    return [self dy_encryption2_0ByDate:dateStamp keys:@[@"password"]];
}

/// 明文 调用 生成 密文2 默认查找 key[password]
-(instancetype)dy_encryption2_1ByDate:(NSString *)dateStamp{
    return [self dy_encryption2_1ByDate:dateStamp keys:@[@"password"]];
}

/// 明文 生成 密文 1
-(instancetype)dy_encryption1WithKeys:(NSArray *)keys{
    NSMutableDictionary *dictM = self.mutableCopy;
    
    for (NSString *key in keys) {
        if ([dictM objectForKey:key]) {
            NSString *password = [dictM objectForKey:key];
            [dictM setObject:[password dy_encryption1] forKey:key];
        }
    }
    
    return dictM.copy;
}

/// 密文1 调用 生成 密文2
-(instancetype)dy_encryption2_0ByDate:(NSString *)dateStamp keys:(NSArray *)keys{
    NSMutableDictionary *dictM = self.mutableCopy;
    
    for (NSString *key in keys) {
        if ([dictM objectForKey:key]) {
            NSString *password = [dictM objectForKey:key];
            [dictM setObject:[password dy_encryption2_0ByDate:dateStamp] forKey:key];
        }
    }
    
    return dictM.copy;
}

/// 明文 调用 生成 密文2
-(instancetype)dy_encryption2_1ByDate:(NSString *)dateStamp keys:(NSArray *)keys{
    NSMutableDictionary *dictM = self.mutableCopy;
    
    for (NSString *key in keys) {
        if ([dictM objectForKey:key]) {
            NSString *password = [dictM objectForKey:key];
            [dictM setObject:[password dy_encryption2_1ByDate:dateStamp] forKey:key];
        }
    }
    
    return dictM.copy;
}

@end
